package com.googlecode.restitory.gae.filter.util;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

public class RequestUtil {

	@SuppressWarnings("unchecked")
	public static List<String> getHeaders(HttpServletRequest request,
			String name) {
		List<String> ret = new ArrayList<String>();
		Enumeration<String> headers = request.getHeaders(name);
		while (headers.hasMoreElements()) {
			ret.add(headers.nextElement());
		}
		return ret;
	}

	public static Integer toInteger(String n) {
		if (n == null || n.trim().length() == 0) {
			return null;
		}
		return new Integer(n);
	}

	public static Long toLong(String n) {
		if (n == null || n.trim().length() == 0) {
			return null;
		}
		return new Long(n);
	}

	public static String[] getParamters(HttpServletRequest request, String name) {
		String[] ret = request.getParameterValues(name);
		if (ret == null) {
			return new String[0];
		}
		return ret;
	}

}
